package com.hspedu.socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/1
 * @time 20:38
 */
public class SocketTCP01Client {
    public static void main(String[] args) throws IOException {
        //1. 创建客户端的套接字
        Socket socket = new Socket(InetAddress.getLocalHost(),9999);
        System.out.println("客户端 socket的类型是"+socket.getClass());

        //2. 根据Socket获取到管道中的流,这里是字节流,写入数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("您好,server".getBytes());

        //3. 关闭相关资源
        outputStream.close();
        socket.close();
        System.out.println("客户端退出");
    }
}
